package com.servlet.book;

import com.enitiy.Book;
import com.service.book.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 创建作者 ：MySunshine
 * 创建时间 2022/10/28 10:58
 * 项目名称 SHUSHAN
 */
@WebServlet("/BookUpdateById")
public class BookUpdateById extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BookServiceImpl bsi = new BookServiceImpl();
        int  id = Integer.parseInt(req.getParameter("bid"));
        System.out.println("id"+id);
        String user = req.getParameter("user");
        String book = req.getParameter("book");
        int kid =Integer.parseInt(req.getParameter("kid")) ;
        String synopsis = req.getParameter("synopsis");
        if (synopsis==null||synopsis.length()<=0){
            Book booko = bsi.SelectBookById(id);
            synopsis=booko.getSynopsis();
        }
        System.out.println(synopsis);
        boolean b = bsi.UpdateBookById(new Book(id, book, user, kid, synopsis));
        if (b){
            System.out.println("修改完成！");
             resp.sendRedirect("/page/dba/dbaBookMge.jsp");
        }else {
            System.out.println("修改失败！");
        }
    }
}
